package uml.FileIO;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

import uml.FileIO.FileScanner.ScanLine;
import uml.GUI.DiagramPanel;
import uml.objects.AnchorPoint;
import uml.objects.UMLObject;

public class FileHandler 
{
	/**
	 * Loads file in diagram
	 * @param file
	 * @param diagram
	 * @return
	 */
	
	public static DiagramPanel open(File file, DiagramPanel diagram)
	{
		Scanner scanner = null;
		try {
			scanner = new Scanner(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ArrayList<ArrayList<ScanLine>> tokens = FileScanner.tokenize(scanner);
		ArrayList<UMLObject> objects = FileParser.parseTokens(tokens);
		for(UMLObject object : objects)
			diagram.add(object);
		return diagram;
	}

}
